home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / CONTAINER / RunArray.h < prev    next >
C/C++ Source or Header  |  1992-04-27  |  3KB  |  119 lines

  1. #ifndef RunArray_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define RunArray_First
  7.  
  8. #include "Object.h"
  9.  
  10. //---- class RunArray --------------------------------------------------
  11.  
  12. enum RArrayGrowDir { eRARight, eRALeft };
  13.  
  14. class RunArray: public Object {
  15. friend class RunArrayIter;
  16.     Object **cont;          // array with objects of runs
  17.     int *runs;         // array with length of runs
  18.     int size;               // size of allocated memory
  19.     int count;              // number of runs
  20.     int length;             // length of runarray
  21.  
  22.     //---- cache
  23.     int theRun;             // the current run
  24.     int runOffset;          // offset of the current run
  25.     
  26.     void OutOfRangeError(char *where, int at);
  27. protected:    
  28.     void MoveTo(int );
  29.     void Shift(int , int);
  30.     void InsertRuns(int, int, Object**, int*, int);
  31.     void CopyRuns(Object**, int*, int, int, int );
  32.     int EndOfRun();
  33.     bool IsInRun(int at);
  34.     void NextRun();
  35.     void PrevRun();
  36.  
  37. public:
  38.     MetaDef(RunArray);               
  39.     //---- creation, destruction  
  40.     RunArray(int elements= 16);                
  41.     ~RunArray();
  42.     void FreeAll();
  43.  
  44.     void Insert(Object *op, int from, int to, int len);
  45.     void ChangeRunSize(int i, int shift, RArrayGrowDir gd);
  46.     void ReplaceRange(int from, int to, RunArray *src, int sfrom, int sto);
  47.  
  48.     void Paste(RunArray *paste, int from, int to);
  49.     void Copy(RunArray *save, int from, int to);
  50.     RunArray* Save(int from, int to);
  51.     void Cut(int from, int to);
  52.  
  53.     Object*& operator[](int i);     
  54.     Object *RunAt(int i, int *start, int *end, int *size ,int *lenat);
  55.     int LengthAt(int i);            
  56.     int RunSizeAt(int i);           
  57.     int NumberOfRuns(); 
  58.     int Size();
  59.     void CheckInvariant();
  60.  
  61.     //---- standard overriden methods 
  62.     OStream& PrintOn(OStream&);
  63.     IStream& ReadFrom(IStream&);
  64.     void InspectorId(char *buf, int sz);
  65. };
  66.  
  67. //---- inlines
  68.   
  69. inline int RunArray::EndOfRun()
  70.     return theRun < count ? runOffset + runs[theRun]: length;
  71. }
  72.     
  73. inline bool RunArray::IsInRun(int at)
  74.     return theRun < count ? at >= runOffset 
  75.           && at < EndOfRun(): at == length;
  76. }
  77.  
  78. inline void RunArray::NextRun()
  79.     runOffset += runs[theRun++]; 
  80. }
  81.  
  82. inline void RunArray::PrevRun()
  83.     runOffset -= runs[--theRun]; 
  84. }
  85.  
  86. inline int RunArray::NumberOfRuns() 
  87.     return count; 
  88. }         
  89.     
  90. inline int RunArray::Size()
  91.     return length; 
  92. }
  93.      
  94. //---- RunArrayIter ---------------------------------------------------
  95.  
  96. class RunArrayIter {
  97.     int ce;         // index of runelement
  98.     int ci;         // index of runarray
  99.     int cp;
  100.  
  101.     RunArray *cs;
  102. public:
  103.     RunArrayIter(RunArray *s);
  104.     Object *operator()();            
  105.     Object *Run(int *start, int *end, int *size);
  106.     // iterate by runs
  107.     Object **RunPtr(int *start, int *end, int *size);
  108.     // iterate by runs and return address of run
  109. };
  110.  
  111. #endif
  112.  
  113.